mydata <- read.csv2("Titanic.csv")
head(mydata)
##   Survived Class Gender
## 1        0     3      0
## 2        0     3      0
## 3        0     3      0
## 4        1     3      1
## 5        1     3      1
## 6        1     3      0

Description:

mydata$Survived <- factor(mydata$Survived, 
                          levels = c(0, 1), 
                          labels = c("No", "Yes"))

mydata$Class <- factor(mydata$Class, 
                      levels = c(1, 2, 3), 
                      labels = c("1st", "2nd", "3rd"))

mydata$Gender <- factor(mydata$Gender, 
                        levels = c(0, 1), 
                        labels = c("M", "F"))

head(mydata)
##   Survived Class Gender
## 1       No   3rd      M
## 2       No   3rd      M
## 3       No   3rd      M
## 4      Yes   3rd      F
## 5      Yes   3rd      F
## 6      Yes   3rd      M
chisq_survived_class <- chisq.test(mydata$Survived, mydata$Class, 
                                   correct = FALSE)

chisq_survived_class
## 
##  Pearson's Chi-squared test
## 
## data:  mydata$Survived and mydata$Class
## X-squared = 127.86, df = 2, p-value < 2.2e-16
addmargins(chisq_survived_class$observed)
##                mydata$Class
## mydata$Survived  1st  2nd  3rd  Sum
##             No   123  158  528  809
##             Yes  200  119  181  500
##             Sum  323  277  709 1309
round(chisq_survived_class$expected, 2)
##                mydata$Class
## mydata$Survived    1st    2nd    3rd
##             No  199.62 171.19 438.18
##             Yes 123.38 105.81 270.82
round(chisq_survived_class$stdres, 2)
##                mydata$Class
## mydata$Survived    1st    2nd    3rd
##             No  -10.11  -1.84  10.25
##             Yes  10.11   1.84 -10.25
addmargins(round(prop.table(chisq_survived_class$observed, 2), 3), 1) 
##                mydata$Class
## mydata$Survived   1st   2nd   3rd
##             No  0.381 0.570 0.745
##             Yes 0.619 0.430 0.255
##             Sum 1.000 1.000 1.000
addmargins(round(prop.table(chisq_survived_class$observed, 1), 3), 2) 
##                mydata$Class
## mydata$Survived   1st   2nd   3rd   Sum
##             No  0.152 0.195 0.653 1.000
##             Yes 0.400 0.238 0.362 1.000
library(effectsize)
effectsize::cramers_v(mydata$Survived, mydata$Class)
## Cramer's V (adj.) |       95% CI
## --------------------------------
## 0.31              | [0.26, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
interpret_cramers_v(0.31)
## [1] "large"
## (Rules: funder2019)
chisq_survived_gender <- chisq.test(mydata$Survived, mydata$Gender, 
                                    correct = TRUE)

chisq_survived_gender
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  mydata$Survived and mydata$Gender
## X-squared = 363.62, df = 1, p-value < 2.2e-16
addmargins(chisq_survived_gender$observed)
##                mydata$Gender
## mydata$Survived    M    F  Sum
##             No   682  127  809
##             Yes  161  339  500
##             Sum  843  466 1309
round(chisq_survived_gender$expected, 2)
##                mydata$Gender
## mydata$Survived   M   F
##             No  521 288
##             Yes 322 178
round(chisq_survived_gender$stdres, 2)
##                mydata$Gender
## mydata$Survived      M      F
##             No   19.13 -19.13
##             Yes -19.13  19.13
addmargins(round(prop.table(chisq_survived_gender$observed, 2), 3), 1) 
##                mydata$Gender
## mydata$Survived     M     F
##             No  0.809 0.273
##             Yes 0.191 0.727
##             Sum 1.000 1.000
addmargins(round(prop.table(chisq_survived_gender$observed, 1), 3), 2) 
##                mydata$Gender
## mydata$Survived     M     F   Sum
##             No  0.843 0.157 1.000
##             Yes 0.322 0.678 1.000
library(effectsize)
effectsize::cramers_v(mydata$Survived, mydata$Gender)
## Cramer's V (adj.) |       95% CI
## --------------------------------
## 0.53              | [0.48, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
interpret_cramers_v(0.53)
## [1] "very large"
## (Rules: funder2019)
library(effectsize)
interpret_oddsratio(11.13, rules = "cohen1988")
## [1] "large"
## (Rules: cohen1988)
fisher.test(mydata$Survived, mydata$Gender)
## 
##  Fisher's Exact Test for Count Data
## 
## data:  mydata$Survived and mydata$Gender
## p-value < 2.2e-16
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
##   8.588113 14.898522
## sample estimates:
## odds ratio 
##   11.27776